jQuery(document).ready(function(){
	_AB_LoginFormAjax("login_form2");
	_AB_ResetPassFormAjax("resetpass_form");
});

function _AB_ResetPassFormAjax(selector_id)
{
	jQuery("#"+selector_id).submit(function(){
		// Hide 'Submit' Button
		$('#rp_submit').hide();
		// status
		$('#rp_status').hide();
		// Show Gif Spinning Rotator
		$('#rp_ajax_loading').show();
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  
		// -- Start AJAX Call --
		$.ajax({  
			type: "POST",
			url: jQuery("#"+selector_id).attr('action'), 
			data: str,  
			success: function(msg){  
				//msg=ajax_string_dim(msg); 
				var myObject = eval('(' + msg + ')');
				
				if (myObject.status == 0) // success
				{
					// Show 'Submit' Button
					// dont show the submit button when success, because, we should redirect page after 3sec
					$('#rp_submit').show();
				}
				else
					setTimeout('go_to_private_page()', 2000); 
				// Hide Gif Spinning Rotator
				$('#rp_ajax_loading').hide();  
				jQuery("#rp_status").html(myObject.text).fadeToggle("normal"); 
				
			}  

		});  

		// -- End AJAX Call --

		return false;
	});
}

function go_to_private_page(){
	window.location.reload(); // Members Area
}

function _AB_LoginFormAjax(selector_id){
	jQuery("#"+selector_id).submit(function(){
        if (jQuery("#agreed2").attr("checked")!= "checked")
        {
            alert(_login_agreed_term2);
            return false;
        }
		// Hide 'Submit' Button
		$('#submit2').hide();
		$('#login_error2').hide();
		// Show Gif Spinning Rotator
		$('#ajax_loading2').show();
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  
		// -- Start AJAX Call --
		$.ajax({  
			type: "POST",
			url: jQuery("#"+selector_id).attr('action'), 
			data: str,  
			success: function(msg){  
				msg=ajax_string_dim(msg); 
				// Show 'Submit' Button
				$('#submit2').show();

				// Hide Gif Spinning Rotator
				$('#ajax_loading2').hide();  

				if(msg == 'OK') // LOGIN OK?
					{  
					var login_response = '<div class="login_success">'+jQuery("#login_success_mess2").html()+'</div> ';  

					$('#submit2').hide();
					jQuery("#login_success2").html(login_response).fadeToggle("normal"); // Refers to 'status'

					// After 3 seconds redirect the 
					setTimeout('go_to_private_page()', 2000); 
				}  
				else // ERROR?
					{  
					var login_response = msg;
					jQuery('#login_error2').html(login_response).fadeToggle("normal").delay(2000).fadeToggle("normal");
				}  

			}  

		});  

		// -- End AJAX Call --

		return false;
	});
}